// 首页导航左侧导航显隐控制
$(document).ready(function () {
    $(document).scroll(function () {
        var scTop = $(document).scrollTop();
        if ($(window).innerWidth() >= 1280) {
            if (scTop >= 550) {
                $(".index-cont-nav,.gotop").show();
            } else {
                $(".index-cont-nav,.gotop").hide();
            }
        }

    });
});


//热门方向
new Vue({
    el: "#groupList",
    data: {
        groups: []
    },
    methods: {
        findGroupList: function () {
            var _this = this;
            axios.get("group?size=10").then(function (response) {
                _this.groups = response.data.data;
                console.log(_this.groups);
            }).catch(function (err) {
                console.log(err);
            });
        },
        //快捷导航显隐
        startGroup: function () {
            $('.citylistbox > .listbox').hover(function () {
                //父类分类列表容器的高度

                $(this).addClass('hover');
                $(this).children('.box').css('display', 'block');
            }, function () {
                $(this).removeClass('hover');
                $(this).children('.box').css('display', 'none');
            });
        }

    },
    created() {
        this.findGroupList();
    },
    updated() {
        this.startGroup();
    }
});

//首页轮播图
new Vue({
    el: "#picture-carousel",
    data: {
        carousels: []
    },
    methods: {
        findCarousels: function () {
            var _this = this;
            axios.get("carousel?size=6").then(function (response) {
                _this.carousels = response.data.data;
                console.log(_this.carousels);
                startRoll();
            }).catch(function (err) {
                console.log(err);
            });
        }
    },
    created() {
        this.findCarousels();
    },
    updated() {
        //开始滚动
        startRoll();
    }
});

//推荐分类
new Vue({
    el: "#recommend-list",
    data: {
        recommends: []
    },
    methods: {
        findRecommends: function () {
            var _this = this;
            axios.get("classify?size=6").then(function (response) {
                _this.recommends = response.data.data;
                console.log(_this.recommends);
            }).catch(function (err) {
                console.log(err);
            });
        },
        link(id) {
            window.open('course?courseClassify=' + id)
        }
    },
    created() {
        this.findRecommends();
    }
});

//推荐课程
new Vue({
    el: "#recommend",
    data: {
        items: []
    },
    methods: {
        findItems: function () {
            var _this = this;
            axios.get("course?limit=10").then(function (response) {
                _this.items = response.data.data;
                console.log(_this.items);
            }).catch(function (err) {
                console.log(err);
            });
        },
        link(id) {
            window.open('course/info/' + id)
        }
    },
    created() {
        this.findItems();
    }
});

//编程入门分类
new Vue({
    el: "#recommend-1",
    data: {
        items: [],
        Active: -1
    },
    methods: {
        findItems: function (level) {
            if (this.Active !== level) {
                this.Active = level;
                var _this = this;
                axios.get("course", {
                    params: {
                        limit: 5,
                        level: level,
                        groupId:2
                    }
                }).then(function (response) {
                    _this.items = response.data.data;
                    console.log(_this.items);
                }).catch(function (err) {
                    console.log(err);
                });
            }
        },
        link(id) {
            window.open('course/info/' + id)
        }
    },
    created() {
        this.findItems(0);
    }


});